package com.exam.system.controller;

import com.exam.system.entity.*;
import com.exam.system.redis.RedisUtils;
import com.exam.system.service.ExamRoleService;
import com.exam.system.service.ExamUserService;
import com.exam.system.utils.JwtUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;
@Api("角色管理类")
@RestController
@CrossOrigin
@RequestMapping("/role/")
public class ExamRoleController {
    @Autowired
    private ExamRoleService examRoleService;

    @RequestMapping("rolelist")
    public ResponseEntity<List<ExamRole>> findAllRole(Integer pageNum, Integer pageSize ) {
        PageHelper.startPage(pageNum, pageSize);
            List<ExamRole> list = examRoleService.findAllRole();
        PageInfo<ExamRole> info   = new PageInfo<>(list);
        return new ResponseEntity(200, "", info);
    }

    @ApiImplicitParam(name = "id", value = "考试信息id")
    @ApiOperation(value = "查看某个角色信息")
    @RequestMapping("/roleview")
    public ResponseEntity<ExamRole> roleView(ExamRole examRole) {
        try {
            examRoleService.findRoleById(examRole.getId());
            return new ResponseEntity<>(200, "查看成功", null);
        } catch (Exception e) {
            return new ResponseEntity<>(400, "查看失败", null);
        }
    }

    @ApiImplicitParam(name = "ExamRole", value = "考试信息id")
    @ApiOperation(value = "修改一条角色信息")
    @RequestMapping("/roleupdate")
    public ResponseEntity<ExamRole> examInfoUpdate(@RequestBody ExamRole examRole) {
        examRoleService.updateById(examRole);
        return new ResponseEntity<>(200, "修改成功", null);

    }



    //添加
    @ApiImplicitParam(name = "ExamRole", value = "考试信息实体类")
    @ApiOperation(value = "添加考试方法")
    @RequestMapping("/add")
    public ResponseEntity<ExamRole> examInfoAdd(@RequestBody ExamRole examRole) {
        examRoleService.insertRole(examRole);
        return new ResponseEntity<>(200, "添加成功", null);
    }
}
